<template>
  <view class="start">

    <view class="user-input">
      <view class="time">
        出生日期
      </view>
      <view  @click="showPicker = true" class="time-show">
        {{timeText}}
      </view>
    </view>

    <view class="mr-commit" @click="commit" :class="sizeStatus ? 'mr-commit-big' : 'mr-commit-small'"></view> 
    <LandscapeModel v-model:show="show" :sonFun="sonFun"/>
    <fui-date-picker minDate="1990-01-01" :show="showPicker" type="3" @change="change" @cancel="showPicker = false"></fui-date-picker>

  </view>
</template>

<script setup lang="ts">
import LandscapeModel from "@/components/Landscape/LandscapeModel.vue";
import { EnumStatus } from "@/utils/constants";

const sizeStatus = ref(false)
const show = ref(false)
const timeText = ref("请选择你的生日")
const showPicker = ref(false)
const emit = defineEmits(['update:defStatus','update:content'])

const change = (e:any)=>{
  timeText.value = e.result
  showPicker.value = false
}

const sonFun = async()=>{
    const data =  {
      timeText:timeText.value,
      loveTime:generateUniqueRandomNumbers(), // 喜欢的人出现时间
      addTime:generateUniqueRandom(),  //结婚时间
      Money:generateUniqueRandomMoney()
    }
    emit('update:defStatus',EnumStatus.RESULT)
    emit('update:content',data)
}

const startTimer = () => {
    setInterval(() => {
        sizeStatus.value =  !sizeStatus.value
    }, 1000); // 每秒执行一次
  };

const commit = async ()=>{
    uni.showLoading({
        title: "加载中",
        icon: "none",
    });
    uni.hideLoading()
    show.value = true
}

const generateUniqueRandomNumbers = ()=> {
  let numbers = new Set();
  while (numbers.size < 3) {
    let randomNumber = Math.floor(Math.random() * 8) + 17; // 生成 17 到 24 之间的随机数
    numbers.add(randomNumber);
  }
  return Array.from(numbers); 
}

const generateUniqueRandom = ()=> {
  let numbers = new Set();
  while (numbers.size < 2) {
    let randomNumber = Math.floor(Math.random() * 8) + 23; 
    numbers.add(randomNumber);
  }
  return Array.from(numbers); 
}

function generateUniqueRandomMoney() {
  let numbers = new Set();
  while (numbers.size < 3) {
    let randomNumber = Math.floor(Math.random() * 12) + 1; // 生成 1 到 12 之间的随机数
    numbers.add(randomNumber);
  }
  return Array.from(numbers); 
}


onMounted(()=>{
      startTimer()
  })
</script>

<style lang="scss" scoped>
.start{
    .user-input{
      position: absolute;
      top: 70%;
      display: flex;
      padding: 10rpx;
      width: 70%;
      left: 15%;
      background: rgb(255,216,221);
      border-radius: 20rpx;
      border: 1rpx solid black;
      view{
        padding: 20rpx;
        border: 1rpx solid black;
        font-size: 28rpx;
        text-align: center;
       
      }
      .time{
        background: rgb(229,98,139);
        border-radius: 20rpx 0 0 20rpx;
        border-right:0rpx ;
        width: 40%;
      }
      .time-show{
        background: white;
        border-radius:0 20rpx  20rpx 0;
        width: 60%;
        }
    }

    .mr-commit{
      z-index: 102;
      position: absolute;
      top: 80%;
      width: 60%;
      height: 100rpx;
      left: 20%;
      background-size: 100% 100%;
      display: flex;
      justify-content: center;
      align-items: center;
      color: white;
      background-image: url("http://img-miniprogram-o.doutuimao.net/miniadmin/programconfig/xcximg/20230524/da807154bd6a5be97416495e47ee8b91.png");
  }
  .mr-commit-big{
      width: 62%;
      height: 105rpx;
      left: 19%;
      transition: all 1s;
  }
  .mr-commit-small{
      width: 60%;
      height: 100rpx;
      left: 20%;
      transition: all 1s;
  }
}

</style>
